const {resolve} = require('path');
const {type} = require("os");
const chromeBrowser = type() === "Windows_NT" ? "chrome" :
	type() === "Darwin" ? "Google Chrome" : "google-chrome"
const htmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
	entry: "./src/index.js",
	output: {
		clean: true, // 在生成文件之前清空 output 目录
		filename: "build.js",
		path: resolve(__dirname, "dist"),
	},
	module: {
		rules: [
			{
				test: /\.js$/,
				exclude: /node_modules/,
				use: {
					loader: "babel-loader",
					options: {
						presets: [
							[
								"@babel/preset-env",
								{
									targets: {
										chrome: "70",
										firefox: "60",
										ie: "9"
									}
								}
							]
						],
						plugins: [
							[
								"@babel/plugin-transform-runtime"// 使用了生成器
							]
						]
					}
				}
			}
		]
	},
	plugins: [
		new htmlWebpackPlugin({
			title: "es6-es11",
			template: "public/index.html",
			minify: {
				removeComments: true,
				collapseWhitespace: true,
				removeAttributeQuotes: true
			}
		})
	],
	mode: "development",
	devServer: {
		port: process.env.npm_package_config_port,
		compress: true,
		open: {
			app: {
				//浏览器应用程序名称与平台相关。不要在可重用模块中硬编码它。例如，'Chrome' 在 macOS 是 'Google Chrome'，在 Linux 是 'google-chrome'，在 Windows 是 'chrome'。
				name: chromeBrowser
			}
		},
		hot: true,
		client:{
			progress: true
		}
	}
}
